import com.tgl.PingApplication
import com.tgl.scheduler.PingScheduler
import com.tgl.util.FileLockUtil;
import org.springframework.boot.test.context.SpringBootTest;
import spock.lang.Specification;

/**
 * @author tonggl
 * @date 2024/7/26 17:42
 * @description TODO
 */
@SpringBootTest(classes = PingApplication.class)
class PingSchedulerTest extends Specification {

    // 测试定时请求-true
    def "test scheduledTask"() {
        // given块
        given: "initial conditions"
        PingScheduler pingScheduler = new PingScheduler();
        // 设置前置条件或数据
        when: "action is performed"
        pingScheduler.scheduledTask();
        then:
        noExceptionThrown()
    }
    // 覆盖分支-true
    def "test scheduledTask2"() {
        // given块
        given: "initial conditions"
        PingScheduler pingScheduler = new PingScheduler();
        // 设置前置条件或数据
        when: "action is performed"
        FileLockUtil.getLock(new File("file1.txt"));

        pingScheduler.scheduledTask();

        then: "expected outcome"
        noExceptionThrown()



    }

    // 测试发送请求-true
    def "test sendPing"() {
        // given块
        given: "initial conditions"
        PingScheduler pingScheduler = new PingScheduler();
        // 设置前置条件或数据
        when: "action is performed"
        expected = pingScheduler.sendPing(parameter).block();
        println expected
        then: "expected outcome"

        where:
        parameter     | expected
        "hello"  | "Parameter is incorrect"
        "Hello"  | "World"
    }


}
